//
//  ChildBoundAdultView.swift
//  AirTravel
//
//  Created by apple on 2021/8/13.
//

import UIKit
import FWPopupView

protocol ChildBoundAdultDelegate:NSObjectProtocol {
    func childBoundAdultClick(dic:Dictionary<String,Any>)
}


class ChildBoundAdultView: FWPopupView {
    var contentView:UIView!
    weak var delegate: ChildBoundAdultDelegate?
    
    @IBOutlet weak var contentTX: UITextView!
    @IBOutlet weak var collView: UICollectionView!
    let identifyCBA = "ChildBoundAdultColl"
    
    
    //关闭
    @IBAction func backBtn(_ sender: Any) {
        self.hide()
        self.hideKeyboard()
    }
    
    // 初始化时将xib中的view添加进来
    override init(frame: CGRect) {
        super.init(frame: frame)
        contentView = loadViewFromNib()
        contentView.frame = self.bounds
        contentView.backgroundColor = UIColor.white
        self.insertSubview(contentView, at: 0)
        
        self.collView.dataSource = self
        self.collView.delegate = self
        let layout1 = UICollectionViewFlowLayout.init()
        layout1.scrollDirection = .vertical
        
        layout1.itemSize = .init(width: (SCREEN_WIDTH - 40) / 2, height: 60)
        layout1.minimumInteritemSpacing = 6
        layout1.sectionInset = UIEdgeInsets.init(top: 6, left: 15, bottom: 6, right: 15)
        self.collView.collectionViewLayout = layout1
        self.collView.register(UINib.init(nibName: "ChildBoundAdultColl", bundle: nil), forCellWithReuseIdentifier: identifyCBA)
        
    }
    
    // 初始化时将xib中的view添加进来
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    // 加载xib
    func loadViewFromNib() -> UIView {
        let className = type(of: self)
        let bundle = Bundle(for: className)
        let name = NSStringFromClass(className).components(separatedBy: ".").last
        let nib = UINib(nibName: name!, bundle: bundle)
        let view = nib.instantiate(withOwner: self, options: nil).first as! UIView
        view.backgroundColor = UIColor.clear
        return view
    }
}

extension ChildBoundAdultView:UICollectionViewDataSource,UICollectionViewDelegate{
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 4
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifyCBA, for: indexPath) as! ChildBoundAdultColl
        cell.backView.layer.cornerRadius = 2
        cell.backView.layer.borderWidth = 1
        cell.backView.layer.borderColor = UIColor.init(hexString: "#ececec").cgColor
        return cell
    }
    
    
}
